const express = require('express')

class Server {
  constructor({ config, router, listener, logger, jwt }) {
    this.app = express()
    this.config = config
    this.app.use(jwt.initialize())
    this.app.use(router)
    this.listener = listener
    this.logger = logger
  }
  async start() {
    return new Promise((resolve) => {
      this.app.listen(this.config.get('port'), () => {
        this.logger.info(
          `[Server] 服务器已启动 ${this.config.get('ip')}:${this.config.get(
            'port'
          )}`
        )
        this.listener.listen()
        resolve()
      })
    })
  }
}

module.exports = Server
